#!/bin/bash

rm authorized_keys
rm users.list
rm timeline.list

mkdir transfer

for i in `echo "select serialnumber from user;" |sqlite3 shackspacekey.sql3`
do
 publickey=`echo "select PublicKey from user where serialnumber = $i;" |sqlite3 shackspacekey.sql3`
 name=`echo "select Givenname,Surname from user where serialnumber = $i;" |sqlite3 shackspacekey.sql3`
 fingerprint=`echo "select fingerprint from user where serialnumber = $i;" |sqlite3 shackspacekey.sql3`
 firstdate=`echo "select strftime('%s',FirstValidDate) from user where serialnumber = $i;" |sqlite3 shackspacekey.sql3`
 lastdate=`echo "select strftime('%s',LastValidDate) from user where serialnumber = $i;" |sqlite3 shackspacekey.sql3`
 echo "$i $fingerprint $name"              >> transfer/users.list
 echo "$i $publickey $firstdate $lastdate" >> transfer/timeline.list
done 

tar cvf transfer.tar transfer
scp -i root.key transfer.tar root@192.168.1.1:/mmc/

scp -i root.key root@192.168.1.1:/mmc/access.log .

cat access.log >> accesslog.log
rm access.log

rm -rf transfer
rm transfer.tar
